package com.cdream.basic.algorithm.leetcode.string;

public class Question28 {
    public int strStr(String haystack, String needle) {
        int nL = needle.length();
        if (nL == 0) {
            return 0;
        }
        if (nL > haystack.length()) {
            return -1;
        }
        int l = haystack.length() - nL;
        for (int i = 0; i <= l; i++) {
            String sub = haystack.substring(i, i + nL);
            if (needle.equals(sub)){
                return i;
            }
        }
        return -1;

    }
}
